package prefuse.treeview;

import java.util.Iterator;


import prefuse.decisiontree.*;
import prefuse.decisiontree.XMLHandler.XMLController;
import prefuse.decisiontree.api.*;
import prefuse.gui.*;
import prefuse.vensim.*;

/**
 * A class that contains Hard Coded Test Case
 * @edit Alan Yeung Wenyi An
 * @author Amy, Yudi Xue, Wenyi An
 */
public class Main {

    private XMLController xmlCtrl;
    public VensimSimulationController simulationController;
//    private DOTController dotCtrl;
    private TreeStructureHandler treeStructure;
    /**
     * Constructor of Main
     * @edit Alan Yeung
     * @author Amy, Yudi Xue, Wenyi An
     */
    public Main()
    {   
    }
    /**
     * initializes the program
     *      - prints welcome message
     *      - creates the tree
     */
    protected void init(){      
    	treeStructure = new TreeStructureHandler();
		xmlCtrl = new XMLController(this);
		simulationController = new VensimSimulationController();
	//	DrawControler drawControler = new DrawControler();
		InterfaceHandler InterfaceHandler = new InterfaceHandler(this);      
    }
   
   
    public TreeStructureHandler getTreeSturcture(){
    	return this.treeStructure;
    }
    /**
     * uses the xml controller to load the specified file
     * @param loadFile - file name to load
     */
    public void loadFromXML(String loadFile)
    {
    	treeStructure.cleanup();
        this.xmlCtrl.load(loadFile);
    }
   
    /**
     * use the xml controller to write to the specified file
     * @param writeFile - file name to write to
     */
    public void writeToXML(String writeFile)
    {
		System.err.println("Initiating output of XML file " + writeFile);
        xmlCtrl.write(writeFile);
		System.err.println("Completed output of XML file " + writeFile);
    }

    /**
     * use the xml controller to write to the specified file
     * @param writeFile - file name to write to
     */
//    public void writeToDOT(String writeFile)
//    {
//         this.dotCtrl.write(writeFile);
//    }

    /**
     * use the simulation controller's init
     * @param modelName - the  modelName to be loaded
     */
    public void simulationInit(String modelName)
    {
        this.simulationController.init(this.treeStructure.getDecisionTree(), modelName);
    }

    public Iterator<String> getSimulationListVarNames()
    {
        return this.simulationController.getVariableNames();
    }

    public Iterator<String> getSimulationListConstantParameterNames()
    {
        return this.simulationController.getConstantParameterNames();
    }
    public String[] getSimulationListVarNamesbyArray()
    {
        return this.simulationController.getVariableNamesbyArray();
    }
    
    /**
     * Perform the simualation with the specified simulation name.  The simulation is assumed to start at the start time of the model
     * @param simulationName - simulation name
     * @deprecated startTime - start time of the simulation
     */
    public void startSimulation(String simulationName /*, double startTime */)
    {
        this.simulationController.startSimulation(simulationName /*, startTime */);
    }
    

    
//    public float[] getVariable(){
//    	return this.simulationController.getvarVar();
//    }
//    
//    public float[] gettimeVariable(){
//    	return this.simulationController.gettimeVar();
//    }
    
    /**
     * Call the tree to perform rollback
     */
    public boolean rollBack(){
        return this.treeStructure.getDecisionTree().rollBack();
    }
    public double catchRollBackFromTree(){
    	return this.treeStructure.getBasicDecisionTree().getrVal();
    }
    public XMLController returnXmlCtr(){
    	return this.xmlCtrl;
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {     
       Main main = new Main();
       main.init();
    }

}
